﻿uap({
    view: function (o, type, name, deep, same) {
        var k, s = this.view.caller == this.view ? '' : 'type[' + typeof o + ']', tp, rn, typeJe = true;
        if (name) {
            rn = ('/' + name + '/i').toJSON();
        }
        if (type) {
            if (type.substr(0, 1) == '!') {
                typeJe = false;
                type = type.substr(1);
            }
        }
        if (typeof o == 'object') {
            for (k in o) {
                if (Array.prototype[k]) continue;
                if (String.prototype[k]) continue;
                if (Number.prototype[k]) continue;
                if (Object.prototype[k]) continue;
                tp = typeof o[k];
                if (type) {
                    if (typeJe) {
                        if (tp != type) continue;
                    } else {
                        if (tp == type) continue;
                    }
                }
                if (rn) if (!rn.test(k)) continue;
                s += '\n';
                if (tp !== 'object') {
                    if (tp !== 'function') {
                        s += k + ' [' + tp + ']';
                        s += ' = ' + o[k];
                    } else {
                        s += k + ' = ' + o[k].toString().substr(0, o[k].toString().indexOf(')') + 1);
                    }
                } else {
                    if (deep) {
                        if (same) {
                            s += k + '={' + this.view(o[k], type, name, false).replace(/\n/g, '\n    ') + '\n}';
                        } else {
                            s += k + '={' + this.view(o[k], null, null, false).replace(/\n/g, '\n    ') + '\n}';
                        }
                    } else {
                        s += k + ' [' + tp + ']';
                    }
                }
            }
        } else {
            s = o;
        }
        if (this.view.caller != this.view) alert(s);
        return s;
    }
});